//
//  CustomTransitionViewController.m
//  ios7Sample
//
//  Created by GeIL on 16/7/13.
//  Copyright © 2016年 KS. All rights reserved.
//

#import "CustomTransitionViewController.h"
#import "HUTransitionAnimator.h"
#import "ZBFailenBricksAnimator.h"

typedef enum {
    TransitonTypeNormal,
    TransitionTypeVerticalLines,
    TransitionTypeHorizontalLines,
    TransitionTypeGravity,
}TransitonType;

@interface CustomTransitionViewController ()<UINavigationControllerDelegate>
{
    TransitonType type;
}

@end

@implementation CustomTransitionViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    type = TransitonTypeNormal;

    self.navigationController.delegate = self;
}

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    
     NSObject <UIViewControllerAnimatedTransitioning> *animator;
    switch (type) {
        case TransitionTypeVerticalLines:
            animator = [[HUTransitionVerticalLinesAnimator alloc] init];
            [(HUTransitionAnimator *)animator setPresenting:NO];
            break;
        case TransitionTypeHorizontalLines:
            animator = [[HUTransitionHorizontalLinesAnimator alloc] init];
            [(HUTransitionAnimator *)animator setPresenting:NO];
            break;
        case TransitionTypeGravity:
            animator = [[ZBFailenBricksAnimator alloc] init];
            break;
        default:
            animator = nil;
    }
    
    return animator;
}


- (IBAction)pop:(UIButton *)sender {
    switch (sender.tag) {
        case 0:
            type = TransitionTypeVerticalLines;
            break;
            
        case 1:
            type = TransitionTypeHorizontalLines;
            break;
            
        case 2:
            type = TransitionTypeGravity;
            break;
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
